/**
 *
 * @author John Creecy
 */

package battlebarnchat;


import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SendChatMessage implements Runnable {

	private String message;

	public SendChatMessage(String messageText) {
		message = messageText;
	}
	public void run() {
		sendMessage();
	}

	public void sendMessage() {
		try {
			DatagramSocket clientSocket = new DatagramSocket();
			InetAddress IPAddress = InetAddress.getByName("johndev");
			byte[] sendData = new byte[1024];
			sendData = message.getBytes();
			DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
			clientSocket.send(sendPacket);
			clientSocket.close();
		} catch (IOException ex) {
			Logger.getLogger(SendChatMessage.class.getName()).log(Level.SEVERE, null, ex);
		}
	}
}
